package com.pagepub.core.tag.validator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidateEmail extends FormValidateBasic {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2482186375840217941L;
	/**
	 * @param args
	 */
	private String submitvalidate;
	
	public String getSubmitvalidate() {
		return submitvalidate;
	}
	public void setSubmitvalidate(String submitvalidate) {
		this.submitvalidate = submitvalidate;
	}
	@Override
	public int doStartTag() throws JspException {
		// TODO 自动生成方法存根
		JspWriter out=this.pageContext.getOut();	   
		try{
		     out.print(this.validateemail());
		//	System.out.println(str);
		}
		catch(Exception e){
			e.printStackTrace();
		}			
		
		return 1;
	}
	public StringBuffer validateemail(){
		StringBuffer str=new StringBuffer();
		String emptyelement="";
	    String pluselement="";
	     if(this.submitvalidate!=null&&this.submitvalidate.equalsIgnoreCase("true")){
				emptyelement="emptyelement(realname);";
				pluselement=" pluselement(realname);";
			}
		str.append(this.returnfunction());
		str.append("<script language=\"javascript\">");
		str.append("function CheckEmail(realvalue,min,max,spanname,realname)");
		str.append("	{");
		str.append("if(realvalue!=\"\"){");
		str.append("if(Checkemailformat(realvalue)){");
		str.append("	message=\"对不起,\"+realname+\"格式不正确！\";");
		str.append("	imgurl=\"<img src=\\\""+this.wrongimage+"\\\"/>\";"); 
		//str.append("alert(realname);");		
		str.append(this.display());
		str.append(pluselement);
		str.append("return false;");
		str.append(" }");
		str.append(" else if(ValidateLength(realvalue,min,max,realname,spanname)){");	
		str.append(this.displayempty());
		str.append(emptyelement);
		str.append("return true;");
		str.append(" }");

		str.append("}");
		  
		str.append("	}");
		str.append("</script>");
		str.append(this.checkemailformat());
		return str;
	}
	public StringBuffer returnfunction(){
		StringBuffer str=new StringBuffer();
		ValidateLength validateLength=new ValidateLength();
		validateLength.setWordcolor(wordcolor);
		validateLength.setWrongimage(wrongimage);
		str.append(validateLength.validatelength());		
		return str;
		
	}
	
}
